<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@page import="java.util.List"%>
<%@page import="com.demoweb.model.dto.Board"%>
<%@page import="com.demoweb.model.dto.Membership"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Red Fortress</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link href="/demoweb/styles/style.css" rel="stylesheet" type="text/css" />
</head>
<body>

<%
	pageContext.include("/WEB-INF/views/include/fortressheader.jsp");
%>

<div id="content">
  <div id="sidebar">
    <div id="login" class="boxed">
      <h2 class="title">Client Account</h2>
      <div class="content">
      
      		 <%
            		 	if (request.getParameter("returnuri") != null) {
            		 %>
		        <%-- <input type="hidden" .. /> : 눈에 보이지 않는 입력 요소 --%>
		        <%
		        	String query = request.getParameter("pageno");
		        		           String returnuri = request.getParameter("returnuri");
		        		   if(query != null && query.length() != 0) {
		        		  	 if(returnuri.contains("?")) {
		        			   	query="&pageno=" + query;
		        		  	 } else {
		        				   query="?pageno=" + query;
		        		   	 }
		        		   } else {
		        			   query = "";
		        		   }
		        %>
		        <input type="hidden" name="returnuri" value='<%=returnuri + query%>' />
		 <%
		 	}
		 %>
		      
		 <%
		      		 	if(session.getAttribute("loginuser") == null)  {
		      		 %>
		  <form id="loginform" method="post" action="fortressLogin.nhn">  
          	<fieldset>
          	<legend>Login</legend>
          	<label for="inputtext1">Client ID:</label>
          	<input id="inputtext1" type="text" name="memberId" value="" />
          	<label for="inputtext2">Password:</label>
          	<input id="inputtext2" type="password" name="passwd" value="" />
          	<input id="inputsubmit1" type="submit" name="inputsubmit1" value="Login" />
          	<p><a href="">Forgot your password?</a></p>
          	</fieldset>
         </form>
	 	<%
	 		} else {
	 	%>	 
	 	 <form id="loginform" method="post" action="fortressLogin.nhn">  
         	 <fieldset>
          	 <legend>Login</legend>
          	 <%
          	 	Membership member = (Membership)session.getAttribute("loginuser");
          	 %>
			 <a2> <%= member.getMemberId() %> 님 환영합니다. </a2>
			 <a href="/demoweb/fortress/fortressLogout.nhn"> 로그아웃</a></br>
		 	 <input type="button" value="Start" style="width:200px" style="hegiht:50px" onclick="location.href='.action';" />
			 <% }  %>      
          	 </fieldset>
         </form>
        
      </div>
    </div>  
    <% pageContext.include("/WEB-INF/views/include/fortressrecentupdates.jsp"); %>
  </div>
  
  <!-- ---------------------------------- Main page content ----------------------------------- -->
  <div id="main"> 
  	  <h2 class="title">Fortress Board</h2>
  	  
  	  <%!String getTitleString(Board board) {
	
		StringBuilder html = new StringBuilder(256);
		if (board.isDeleted()) {
			html.append("<span style='color:gray' ");
			html.append("onclick=\"alert('삭제된 글입니다.');\">");
			html.append(board.getTitle());
			html.append("&nbsp;(삭제된 글)");
			html.append("</span>");
		} else {
			html.append("<a href='javascript:viewboard(");
			html.append(board.getBoardNo());
			html.append(");'>");
			html.append(board.getTitle());
			html.append("</a>");
		}
			return html.toString();
		}%>

	<script type="text/javascript">
	function viewboard(boardno) {
		
		<%
		String pageNo = request.getParameter("pageno");
		if (pageNo == null || pageNo.length() == 0)
			pageNo = "1";
		%>
		
		<% if (session.getAttribute("loginuser") != null) { %>
		location.href = 
			'fortressBoardview.nhn?boardno=' + boardno + "&pageno=<%= pageNo %>";
		<% } else { %>
		location.href = 
			"/demoweb/account/loginform.action?" + 
			"returnuri=/demoweb/board/view.action?boardno=" + 
			boardno + "&pageno=<%= pageNo %>";
		<% } %>
	}
	</script>
	
	<div id="pageContainer">
		
		<div style="padding-top:25px;text-align:center">

			<input type="button" value="글쓰기" 
				style="width:300px;height:25px"
				onclick="location.href='fortresswriteform.nhn';" />
			<br /><br />
			
			<% List<Board> boards = (List<Board>)request.getAttribute("boards"); %>
			<% if (boards != null && boards.size() > 0) { %>
			<table border="1" align="center">
				<tr style="background-color:beige;height:25px">
					<th style="width:50px">번호</th>
					<th style="width:300px">제목</th>
					<th style="width:150px">작성자</th>
					<th style="width:120px">작성일</th>
					<th style="width:80px">조회수</th>
				</tr>
				<% for (Board board : boards) { %>				
				<tr style="height:25px">
					<td style="text-align:center"><%= board.getBoardNo() %></td>
					<td style="text-align:left;padding:5px">
						<%-- 
						<a href="view.action?boardno=<%= board.getBoardNo() %>">
						--%>
						<%-- 
						<a href="javascript:viewboard(<%= board.getBoardNo() %>);">
						<%= board.getTitle() %>
						</a>
						--%>
						<%= getTitleString(board) %>
					</td>
					<td style="text-align:center"><%= board.getWriter() %></td>
					<td style="text-align:center"><%= board.getRegDate() %></td>
					<td style="text-align:center"><%= board.getReadCount() %></td>
				</tr>
				<% } %>
			</table>
			<% } else { %>
				<div style='text-align:center'>등록된 게시물이 없습니다.</div>
			<% } %>
			<br /><br />
			
			<%= request.getAttribute("pager").toString() %>
	
		</div>
	</div>
      
  </div>
  <!-- -------------------------------------------------------------------------------------------- -->
  
</div>
<div id="footer">
  <p id="legal">Copyright &copy; 2007 Red Avenue. All Rights Reserved. Designed by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a>.</p>
  <p id="links"><a href="http://www.free-css.com/">Home</a> | <a href="http://www.free-css.com/">Terms of Use</a></p>
</div>
</body>
</html>
